package com.sds.sweng.swat.miplatform.ui.design.models.commands;

import org.eclipse.gef.commands.Command;

import com.sds.sweng.swat.miplatform.ui.design.models.MiplatformComponent;
import com.sds.sweng.swat.miplatform.ui.design.models.MiplatformContainer;

public class ReorderPartCommand extends Command {

	private MiplatformContainer parent;
	private MiplatformComponent child;
	private int oldIndex, newIndex;

	public ReorderPartCommand(MiplatformContainer parent, MiplatformComponent child, int newIndex) {
		this.parent = parent;
		this.child = child;
		this.newIndex = newIndex;
	}

	public void execute() {
		oldIndex = parent.getChildren().indexOf(child);
		parent.removeChild(child);
		parent.addChild(child, newIndex);
	}

	public void undo() {
		parent.removeChild(child);
		parent.addChild(child, oldIndex);
	}

}
